package com.huajx.tuopuda.client.udp.codec.time.interval;

import com.huajx.tuopuda.client.udp.TuopudaDirect;
import com.huajx.tuopuda.client.udp.TuopudaUtil;
import com.huajx.tuopuda.client.udp.codec.AbstractCodec;

/**
 * 读取时段
 *
 * 9.2.3.9.1读取控制时段[1096]
 *
 * @author: lisa 叶新华
 * @create: 2019-09-28 18:13
 */
public class ReadTimeIntervalCodec extends AbstractCodec {
    private int function = TuopudaDirect.D_1096;
    private int timeIndex;

    public ReadTimeIntervalCodec(int sn, int timeIndex) {
        setSn(sn);
        this.timeIndex = timeIndex;
    }

    public static ReadTimeIntervalCodec getInstance(int sn, int timeIndex) {
        return new ReadTimeIntervalCodec(sn, timeIndex);
    }

    @Override
    public byte[] encode() {
        return encode(getSn(), function, bytes -> TuopudaUtil.replaceBytes(bytes, timeIndex, 5, 2));
    }
}
